package org.xwb.springcloud.messagetype.deadletter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import org.xwb.springcloud.constant.MqDeadLetterConstant;

import javax.annotation.Resource;

/**
 * @author Administrator
 */
@Component
public class DeadLetterProducer {
    private static final Logger log = LoggerFactory.getLogger(DeadLetterProducer.class);

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void senderDeadLetterMessage(String message) {
        log.info("\n生产者DeadLetter发送消息:【{}】\n", message);
        //参数1：交换机名称
        //参数2：路由key
        //参数3：消息
        //topic_exchange交换机  需要指定路由key  绑定到该交换机且符合路由key的队列都会收到消息
        rabbitTemplate.convertAndSend(MqDeadLetterConstant.BUSINESS_EXCHANGE, MqDeadLetterConstant.BUSINESS_ROUTING_KEY, message);
    }
}
